
#pragma implementation "jncImportNamespace.h"

#include <boost/function.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/lambda/algorithm.hpp>
#include <functional>
#include <string>
#include <list>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <iterator>
#include <iostream>

#define ARRSZ(arr, type)     sizeof(arr)/sizeof(type)


template<class T>
void registerHandler(T* o, std::list<std::string> tagseq, std::list<jncTypei> typeseq, std::pair<gnCallback, gnCallback> clbs, Priority lvl)
{
  HandlerTable HandlerDb(*AllocNamespaceTable());
  HandlerDb << __entry<T>(o,				
			  new std::list<std::string>(tagseq),
			  new std::list<jncTypei>(typeseq),
			  new std::pair<gnCallback, gnCallback>(clbs),
			  lvl);
}

// This is simply to separate implementation 
// from it's declaration however it will be included
// in jncImportNamespace.h since templates required
// that all implementation be visible at the time
// of instanciation.

#define CALLBACKSEQ(n, type, Cbextractor, Cblauncher)			\
  std::pair<void*, void*>(new , new)

#define REGISTOBJBODY(z, n, data)					\
  {									\
    std::list<std::string> fn_sb;					\
    for(int i = 0 ; tag[i] != NULL; i++)				\
      fn_sb.push_back(tag[i]);						\
    std::list<jncTypei> fn_type(fn_sb.size());				\
    std::copy(typ, (typ + fn_type.size()), fn_type.begin());		\
    assert(o && fn_sb.size() && fn_type.size());			\
    boost::function1<gReturnCode, data*>* cbext = new boost::function1<gReturnCode, data*>(BOOST_PP_IF(IN__CONS__, NULL, Cbextractor)); \
    BOOST_PP_CAT(boost::function, BOOST_PP_INC(n))<gReturnCode, data* BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, OUTPUTARGLIST, jncTypev)>* clblnch = new BOOST_PP_CAT(boost::function, BOOST_PP_INC(n))<gReturnCode, data* BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, OUTPUTARGLIST, jncTypev)>(Cblauncher); \
    std::pair<gnCallback, gnCallback> clbs(cbext, clblnch); \
    registerHandler(o, fn_sb, fn_type, clbs, level);		  \
  }

